package com.Component;

import com.Service.UserService;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-11-15
 * Time: 21:48
 */
//@Component
public class BeanLifeComponent implements BeanNameAware {
    @Override
    public void setBeanName(String s) {
        System.out.println("执行了BeanNaneAware 通知 "+s);
    }
    @Autowired
    private UserService userService;
    /**
     * 方法名随意定义
     * xml中init-method指定的方法
     */
    public void initMethod() {
        System.out.println("执行了init method 方法");
    }

    /**
     * 方法名可以随便取
     */
    @PostConstruct
    public void myPostConstruct() {
        userService.doService();
        System.out.println("执行了PostConstruct 方法");
    }

    /**
     * 销毁前执行方法
     */
    @PreDestroy
    public void myPreDestroy() {
        System.out.println("执行了PreDestroy 方法");
    }
    public void use() {
        System.out.println("执行了use方法(使用Bean)");
    }
}
